Skip to content

Improve how identifiers are treated #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 10, 2025

Conversation

stIncMale
Copy link
Member

No description provided.

@stIncMale stIncMale self-assigned this Apr 4, 2025
@stIncMale stIncMale force-pushed the improveHowItentifiersAreTreated branch from 2ef6d47 to 4f9ef0e Compare April 4, 2025 22:33

@Override
public @Nullable String toQuotedIdentifier(@Nullable String name) {
return name;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This single change makes all the new tests pass, and without it, they all fail. Nothing else related to quoting both in Dialect (including Dialect.buildIdentifierHelper) and in DatabaseMetaData had any observable effect on the tests added.

Copy link
Contributor

@NathanQingyangXu NathanQingyangXu Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a great news! Thanks for your PR. With some minor changes it could be merged.

static final String COLLECTION_NAME = "\"collection in double quotes Mixed Case\"";
static final String FIELD_NAME = "\"field in double quotes Mixed Case\"";
static final String ACTUAL_COLLECTION_NAME = "collection in double quotes Mixed Case";
static final String ACTUAL_FIELD_NAME = "field in double quotes Mixed Case";
Copy link
Member Author

@stIncMale stIncMale Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it seems impossible to prevent Hibernate ORM from stripping identifiers like \"collection in double quotes Mixed Case\" of their quotes. Apparently, it has logic somewhere that ignores any configuration/overrides related to quoting, and strips double and single quotes anyway.

Copy link
Member Author

@stIncMale stIncMale Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That place seems to be here https://github.com/hibernate/hibernate-orm/blob/0a4d551b32801ae15e99d2f8ac0750303ecda2b6/hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java#L159-L173 - it always considers identifiers enclosed in a set of statically-defined characters as quoted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it seems so. If the Hibernate quoting at the start and end is hard-coded or not configurable, I think we could remove those MixedCases testing cases for we don't need to test Hibernate if its behaviour is working as expected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MixedCases tests are for testing that Hibernate ORM does not change the characters in collection/field names with mixed case to upper-/lower-case characters. Currently there is only one test (withSpaceAndDotAndMixedCase) left checking that. Do you still think we should not test this?


@Entity
@Table(name = InSingleQuotesMixedCase.COLLECTION_NAME)
static class InSingleQuotesMixedCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the MixedCase is a little bit unclear, though further code reading shows that the Mixed case simply means single quotes both at the beginning and at the end.

Optional. Avoid the confusing MixedCase here by using more intuitive verbiage like InSingleQuotesDelimiters or simply StartingAndEndingWithSingleQuote.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though further code reading shows that the Mixed case simply means single quotes both at the beginning and at the end.

No, "Mixed Case" means what is usually does - text containing both uppercase and lowercase letters. Since it wasn't clear, I removed it from all but one place in 96b8c78.

static final String COLLECTION_NAME = "\"collection in double quotes Mixed Case\"";
static final String FIELD_NAME = "\"field in double quotes Mixed Case\"";
static final String ACTUAL_COLLECTION_NAME = "collection in double quotes Mixed Case";
static final String ACTUAL_FIELD_NAME = "field in double quotes Mixed Case";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it seems so. If the Hibernate quoting at the start and end is hard-coded or not configurable, I think we could remove those MixedCases testing cases for we don't need to test Hibernate if its behaviour is working as expected.


@Override
public @Nullable String toQuotedIdentifier(@Nullable String name) {
return name;
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a great news! Thanks for your PR. With some minor changes it could be merged.

@stIncMale stIncMale merged commit cc81465 into mongodb:main Apr 10, 2025
6 checks passed
@stIncMale stIncMale deleted the improveHowItentifiersAreTreated branch April 10, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants